package cn.fuxi2022.module.excel.service.impl;

import cn.fuxi2022.module.excel.mapper.ExcelUseDataMapper;
import cn.fuxi2022.module.excel.pojo.DemoData;
import cn.fuxi2022.module.excel.service.ExcelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {

    @Autowired
    private ExcelUseDataMapper excelUseDataMapper;

    @Override
    public List<DemoData> getDemoList() {
        List<DemoData> demoDatas = excelUseDataMapper.selectInfo();

        // 开始进一步处理数据
        demoDatas.forEach(demoData -> {
            // 1.判断用户状态
            if (!StringUtils.hasText(demoData.getStatus())) {
                demoData.setStatus("登录未入社");
            } else if ("0".equals(demoData.getStatus())) {
                demoData.setStatus("登录未入社");
            } else if ("1".equals(demoData.getStatus())) {
                demoData.setStatus("社费未支付");
                demoData.setSuccessfulTime(null);
                demoData.setUseTime(null);
            } else if ("2".equals(demoData.getStatus())) {
                demoData.setStatus("未加群");
                getPayInfo(demoData);
                demoData.setSignCount(excelUseDataMapper.selectRegisterCount(demoData.getStudentId()));
            } else if ("3".equals(demoData.getStatus())) {
                demoData.setStatus("入社成功");
                getPayInfo(demoData);
                demoData.setSignCount(excelUseDataMapper.selectRegisterCount(demoData.getStudentId()));
            }
            // 2.设置性别
            if (StringUtils.hasText(demoData.getSex())) {
                switch (demoData.getSex()) {
                    case "1":
                        demoData.setSex("女");
                        break;
                    case "2":
                        demoData.setSex("男");
                        break;
                    default:
                        demoData.setSex("未知");
                        break;
                }
            }
            // 3.设置学院
            if (StringUtils.hasText(demoData.getCollegeName())) {
                switch (demoData.getCollegeName()) {
                    case "0":
                        demoData.setCollegeName("其他");
                        break;
                    case "1":
                        demoData.setCollegeName("信息技术学院");
                        break;
                    case "2":
                        demoData.setCollegeName("电气与电子工程学院");
                        break;
                    case "3":
                        demoData.setCollegeName("艺术系");
                        break;
                    case "4":
                        demoData.setCollegeName("体育系");
                        break;
                    case "5":
                        demoData.setCollegeName("经济管理学院");
                        break;
                    case "6":
                        demoData.setCollegeName("建设学院");
                        break;
                    case "7":
                        demoData.setCollegeName("外国语学院");
                        break;
                    case "8":
                        demoData.setCollegeName("智能制造学院");
                        break;
                    case "9":
                        demoData.setCollegeName("会计学院");
                        break;
                    default:
                        break;
                }
            }

            // 4.设置学习程度
            if (StringUtils.hasText(demoData.getLevel())) {
                switch (demoData.getLevel()) {
                    case "1":
                        demoData.setLevel("小白");
                        break;
                    case "2":
                        demoData.setLevel("菜鸟");
                        break;
                    case "3":
                        demoData.setLevel("老鸟");
                        break;
                    default:
                        demoData.setLevel("未确定");
                }
            }

            // 5.设置学习方向
            if (StringUtils.hasText(demoData.getDirection())) {
                switch (demoData.getDirection()) {
                    case "1":
                        demoData.setDirection("嵌入式");
                        break;
                    case "2":
                        demoData.setDirection("前端");
                        break;
                    case "3":
                        demoData.setDirection("后端");
                        break;
                    default:
                        demoData.setDirection("未确定");
                }
            }
        });
        return demoDatas;
    }


    public void getPayInfo(DemoData demoData) {
        DemoData temp = excelUseDataMapper.selectPay(demoData.getStudentId());
        demoData.setOrderNo(temp.getOrderNo());
        demoData.setOrderTime(temp.getOrderTime());
        demoData.setOrderCount(excelUseDataMapper.selectPayOrderCount(demoData.getStudentId()));
    }

}
